(function (w) {
  (function ($a) {
    let $w = {
      crtDom(el, elns) {
        if (el.startsWith("<") && el.endsWith(">")) {
          el = el.replace("<", "").replace(">", "");
        }
        if (elns) return document.createElementNS(elns, el);
        return document.createElement(el);
      },
      getEleArr(el) {
        return document.querySelectorAll(el);
      },
      cache: {},
    };
    let dom = function (arg) {
      let crGetEle = function (el, opt, ans) {
        if (el.startsWith("<") && el.endsWith(">")) {
          let n = $w.crtDom(el, (opt || {})["elns"]);
          if (opt) {
            delete opt["elns"];
            for (let k in opt) {
              n.setAttribute(k, opt[k]);
            }
          }
          if (ans) {
            for (let k in ans) {
              n.setAttributeNS(k, ans[k]);
            }
          }
          return [n];
        } else {
          return $w.getEleArr(el);
        }
      };
      let _el = arg[0];
      if (typeof _el == "string") {
        this.selector = _el;
        if (this.selector) {
          this.$elArr = [];
          _el.split(",").forEach((el) => {
            let els = crGetEle(el, arg[1], arg[2]);
            els.forEach((e) => {
              this.$elArr.push(e);
            });
          });
          this.$el = this.$elArr[0];
        }
      } else if (_el instanceof Array) {
        this.selector = "_el_arr";
        this.$el = _el[0];
        this.$elArr = _el;
      } else {
        if (_el.$el) {
          this.selector = _el.selector;
          this.$el = _el.$el;
          this.$elArr = _el.$elArr;
        } else {
          this.selector = _el.tagName;
          this.$el = _el;
          this.$elArr = [_el];
        }
      }
    };
    dom.prototype = {
      attr(n, v) {
        let elArr = this.$elArr;
        if (typeof n == "string") {
          let el = this.$el;
          if (typeof v == "undefined") return el.getAttribute(n);
          else el.setAttribute(n, v);
        } else {
          elArr.forEach((el) => {
            for (let k in n) {
              el.setAttribute(k, n[k]);
            }
          });
        }
        return this;
      },
      removeAttr(attr) {
        if (attr instanceof Array) {
          attr.forEach((c) => {
            this.removeAttr(c);
          });
        } else {
          let elArr = this.$elArr;
          elArr.forEach((el) => {
            el.removeAttribute(attr);
          });
        }
        return this;
      },
      data(k, v) {
        let el = this.$el;
        if (!k) return el.dataset;
        if (typeof k == "string") {
          if (v) {
            el.dataset[k] = v;
          } else {
            return el.dataset[k];
          }
        } else {
          for (let p in k) {
            el.dataset[p] = k[p];
          }
        }
        return this;
      },
      removeData(k) {
        let el = this.$el;
        delete el.dataset[k];
        return this;
      },
      dataAll(o) {
        let el = this.$el;
        for (let k in o) {
          el.dataset[k] = o[k];
        }
        return this;
      },
      offset(t) {
        let el = this.$el;
        if (t) {
          return el.getBoundingClientRect()[t];
        }
        return el.getBoundingClientRect();
      },
      getCls() {
        let el = this.$el;
        let clsName = el.getAttribute("class");
        if (!clsName) return [];
        let clsArr = clsName.split(" ");
        return clsArr;
      },
      hasCls(cls) {
        let el = this.$el;
        let clsName = el.getAttribute("class");
        if (!clsName) return false;
        let clsArr = clsName.split(" ");
        return clsArr.indexOf(cls) >= 0;
      },
      addCls(cls) {
        if (!cls) return this;
        let elArr = this.$elArr;
        if (cls instanceof Array) {
          cls.forEach((c) => {
            this.addCls(c);
          });
        } else {
          elArr.forEach((el) => {
            let clsName = el.getAttribute("class");
            let clsArr = clsName ? clsName.split(" ") : [];
            let idx = clsArr.indexOf(cls);
            if (idx < 0) {
              clsArr.push(cls);
              clsName = clsArr.join(" ");
              el.setAttribute("class", clsName);
            }
          });
        }
        return this;
      },
      removeCls(cls) {
        if (!cls) return this;
        let elArr = this.$elArr;
        if (cls instanceof Array) {
          cls.forEach((c) => {
            this.removeCls(c);
          });
        } else {
          elArr.forEach((el) => {
            let clsName = el.getAttribute("class");
            if (!clsName) return this;
            let clsArr = clsName.split(" ");
            let idx = clsArr.indexOf(cls);
            if (idx >= 0) {
              let nArr = [];
              for (let i = 0; i < clsArr.length; i++) {
                clsArr[i] != cls ? nArr.push(clsArr[i]) : null;
              }
              clsName = nArr.join(" ");
              el.setAttribute("class", clsName);
            }
          });
        }
        return this;
      },
      toggleCls(a, b) {
        if (typeof a === "boolean") {
          a ? this.addCls(b) : this.removeCls(b);
          return this;
        }
        let c = a;
        let d = b;
        if (typeof a === "function") {
          c = a();
        }
        if (typeof b === "function") {
          d = b();
        }
        this.hasCls(c)
          ? this.removeCls(c).addCls(d)
          : this.addCls(c).removeCls(d);
        return this;
      },
      firstChild() {
        let el = this.$el;
        let fc = el.children[0];
        return new dom([fc]);
      },
      cloneNode(p) {
        let el = this.$el;
        let cn = el.cloneNode(p);
        return new dom([cn]);
      },
      remove() {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.remove();
        });
      },
      append(c) {
        if (!c) return this;
        let elArr = this.$elArr;
        if (typeof c == "string") {
          elArr.forEach((el) => {
            el.appendChild($w.crtDom(c));
          });
        } else if (c instanceof Array) {
          c.forEach((el) => {
            this.append(el);
          });
        } else {
          elArr.forEach((el) => {
            el.appendChild(c.$el || c);
          });
        }
        return this;
      },
      prepend(c) {
        if (!c) return this;
        let elArr = this.$elArr;
        if (typeof c == "string") {
          elArr.forEach((el) => {
            el.insertBefore($w.crtDom(c), el.childNodes[0]);
          });
        } else {
          elArr.forEach((el) => {
            el.insertBefore(c.$el || c, el.childNodes[0]);
          });
        }
        return this;
      },
      appendTo(p) {
        let el = this.$el;
        if (typeof p === "string") {
          p = new dom([p]);
        }
        p.$el.appendChild(el);
        return this;
      },
      text(t) {
        let elArr = this.$elArr;
        if (typeof t != "undefined") {
          elArr.forEach((el) => {
            el.innerText = t;
          });
          return this;
        }
        return this.$el.innerText;
      },
      html(h) {
        let elArr = this.$elArr;
        if (typeof h != "undefined") {
          elArr.forEach((el) => {
            el.innerHTML = h;
          });
          return this;
        }
        return this.$el.innerHTML;
      },
      appendText(t) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.innerText += t;
        });
        return this;
      },
      prependText(t) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.innerText = t + el.innerText;
        });
        return this;
      },
      appendHtml(h) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.innerHTML += h;
        });
        return this;
      },
      prependHtml(h) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.innerHTML = h + el.innerHTML;
        });
        return this;
      },
      val(v) {
        let elArr = this.$elArr;
        if (typeof v != "undefined") {
          elArr.forEach((el) => {
            el.value = v;
          });
          return this;
        }
        return this.$el.value;
      },
      click(fn, stop, options) {
        let Ths = this;
        let elArr = Ths.$elArr;
        elArr.forEach((el) => {
          if (fn) {
            let $el = new dom([el]);
            el.addEventListener(
              "click",
              fn.name
                ? fn
                : function (e) {
                    stop ? e.stopPropagation() : null;
                    fn.call($el, $el, e);
                  },
              options,
            );
          } else {
            el.click();
          }
        });
        return this;
      },
      bind(ev, fn, stop, options) {
        let Ths = this;
        let elArr = Ths.$elArr;
        elArr.forEach((el) => {
          let $el = new dom([el]);
          el.addEventListener(
            ev,
            fn.name
              ? fn
              : function (e) {
                  stop ? e.stopPropagation() : null;
                  fn.call($el, $el, e);
                },
            options,
          );
        });
        return this;
      },
      unbind(ev, fn, options) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.removeEventListener(ev, fn, options);
        });
        return this;
      },
      on(ev, fn, stop, options) {
        let Ths = this;
        let key = _$tfn.join("ev-on-", Ths.selector, "-", ev);
        let eventObject = $w.cache[key] || {};
        let evFns = eventObject.fns || [];
        evFns.push(fn);
        let callback = function (e) {
          let eventObject = $w.cache[key] || {};
          let fns = eventObject.fns;
          let exist = false;
          for (let f of fns) {
            if (f === fn) {
              exist = true;
              break;
            }
          }
          if (fns && fns.length && exist) {
            let elArr = $a.document.querySelectorAll(Ths.selector);
            for (let el of elArr) {
              if (el === e.target || el.contains(e.target)) {
                let $el = new dom([el]);
                fn.call($el, $el, e);
                return;
              }
            }
          }
        };
        $w.cache[key] = {
          selector: Ths.selector,
          fns: evFns,
          callback: callback,
        };
        $a.addEventListener(ev, callback, options);
        return Ths;
      },
      off(ev, fn, options) {
        let Ths = this;
        let key = _$tfn.join("ev-on-", Ths.selector, "-", ev);
        let eventObject = $w.cache[key] || {};
        let evFns = eventObject.fns || [];
        evFns.splice(evFns.indexOf(fn), 1);
        if (!evFns.length) {
          let callback = eventObject.callback;
          $a.removeEventListener(ev, callback, options);
          delete $w.cache[key];
        }
        return Ths;
      },
      show() {
        this.css("display", "block");
        return this;
      },
      hide() {
        this.css("display", "none");
        return this;
      },
      css(n, c) {
        let elArr = this.$elArr;
        if (typeof n == "string") {
          if (typeof c == "undefined") {
            return elArr[0].style[n];
          }
        }
        elArr.forEach((el) => {
          if (typeof n == "string") {
            el.style[n] = c;
          } else {
            for (let k in n) {
              el.style[k] = n[k];
            }
          }
        });
        return this;
      },
      removeCss(n) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el.style[n] = "";
        });
        return this;
      },
      parent() {
        let el = this.$el;
        let parentEl = el.parentElement;
        if (parentEl) return new dom([parentEl]);
        else return null;
      },
      parents(s) {
        let pel = this.parent();
        if (pel.$el == $a.document.body) return null;
        return pel.$el.matches(s) ? pel : pel.parents(s);
      },
      match(s) {
        let elArr = this.$elArr;
        let r = null;
        elArr.some((el) => {
          if (el.matches(s)) {
            r = new dom([el]);
            return true;
          }
        });
        return r;
      },
      matches(s) {
        let elArr = this.$elArr;
        let r = [];
        elArr.some((el) => {
          if (el.matches(s)) {
            r.push(el);
          }
        });
        return new dom([r]);
      },
      find(s) {
        let elArr = this.$elArr;
        let r = null;
        elArr.some((el) => {
          let f = el.querySelectorAll(s);
          if (f && f.length > 0) {
            r = new dom([f[0]]);
            return true;
          }
        });
        return r;
      },
      findAll(s) {
        let elArr = this.$elArr;
        let arr = [];
        elArr.forEach((el) => {
          for (let f of el.querySelectorAll(s)) {
            arr.push(f);
          }
        });
        return new dom([arr]);
      },
      findByAttr(a, s) {
        let el = this.$el;
        let arr = [];
        for (let c of el.children) {
          if (c.getAttribute(a) == s) {
            arr.push(c);
          }
        }
        return new dom([arr]);
      },
      prev() {
        let el = this.$el;
        let prev = el.previousElementSibling;
        return prev ? new dom([prev]) : null;
      },
      next() {
        let el = this.$el;
        let next = el.nextElementSibling;
        return next ? new dom([next]) : null;
      },
      children(i) {
        let el = this.$el;
        if (i) {
          let c = el.children[i];
          return new dom([c]);
        }
        let arr = [];
        for (let c of el.children) {
          arr.push(c);
        }
        return new dom([arr]);
      },
      findByTag(s) {
        let el = this.$el;
        let arr = [];
        let t = el.getElementsByTagName(s);
        for (let i = 0; i < t.length; i++) {
          arr.push(t[i]);
        }
        return new dom([arr]);
      },
      get(a) {
        let el = this.$el;
        return el[a];
      },
      set(a, b) {
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          el[a] = b;
        });
        return this;
      },
      attrNs(n, k, v) {
        let el = this.$el;
        if (typeof k == "string") {
          if (typeof v == "undefined") return el.getAttributeNS(n, k);
          else el.setAttributeNs(n, k, v);
        } else {
          for (let p in k) {
            el.setAttributeNs(n, p, k[p]);
          }
        }
        return this;
      },
      eq(i) {
        return new dom([this.$elArr[i]]);
      },
      len() {
        return this.$elArr.length;
      },
      toArr() {
        let eArr = [];
        let elArr = this.$elArr;
        elArr.forEach((el) => {
          eArr.push(new dom([el]));
        });
        return eArr;
      },
      each(fn) {
        let elArr = this.$elArr;
        elArr.forEach((el, idx) => {
          fn(new dom([el]), idx);
        });
        return this;
      },
    };
    let $win = (...args) => {
      if (typeof args[0] === "function") {
        let doc = $a.document;
        if (doc.body) {
          args[0]();
        } else {
          doc.addEventListener(
            "DOMContentLoaded",
            () => {
              args[0]();
            },
            false,
          );
        }
      } else {
        return new dom(args);
      }
    };
    let o, k;
    for (k in (o = {
      fn: dom.prototype,
      crtDom: $w.crtDom,
      extend() {
        if (typeof arguments[0] == "string") {
          dom.prototype[arguments[0]] = arguments[1];
        } else if (typeof arguments[0] == "function") {
          let fn = arguments[0];
          let fname = fn.name;
          if (!fname) {
            throw "function name is empty !!";
          }
          dom.prototype[fname] = fn;
        } else {
          let len_ = arguments.length;
          if (len_ < 1 || !arguments[0]) {
            return {};
          }
          let ed_ = function (destination_, source_) {
            if (Array == source_.constructor) {
              for (let i_ = 0; i_ < source_.length; i_++) {
                destination_.push(source_[i_]);
              }
            } else {
              for (let p_ in source_) {
                destination_[p_] = source_[p_];
              }
            }
          };
          for (let i_ = 1; i_ < len_; i_++) {
            arguments[i_] ? ed_(arguments[0], arguments[i_]) : null;
          }
          return arguments[0];
        }
      },
    })) {
      $win[k] = o[k];
    }
    let _$tfn = this.call($win, $a);
    return {
      $(o) {
        $a[$a.atob(o)] = $win;
      },
    };
  })
    .call(this, w)
    .$("JCQ=");
}).call(function ($w) {
  let $Doc = $w.document;
  let $Ths = this;
  let fn = {
    debounce(func, wait) {
      if (!!$w.debounce_timeout_) {
        clearTimeout($w.debounce_timeout_);
      }
      $w.debounce_timeout_ = setTimeout(func, wait || 200);
    },
    getParam: (k) => {
      let us_ = decodeURI(decodeURI($Doc.location.search + "")).replace(
        "?",
        "",
      );
      if (us_ == "") {
        return null;
      }
      let param = {};
      let pms = us_.split("&");
      for (let i = 0; i < pms.length; i++) {
        if (pms[i].indexOf("=") == -1) {
          continue;
        }
        let p_ = pms[i].split("=");
        if (k && k == p_[0]) {
          return p_[1];
        }
        param[p_[0]] = p_[1];
      }
      return k ? null : param;
    },
    ajax: (o) => {
      if (!o.url) {
        throw new Error("Missing 'url' parameter !");
      }
      let $en_ = encodeURIComponent;
      let $gP_ = function (p1, p2) {
        return $en_($en_(p1)) + "=" + $en_($en_(p2));
      };
      let $pP_ = function (p1, p2) {
        return $en_(p1) + "=" + $en_(p2);
      };
      let u_ = o.url;
      let t_ = o.type || "POST";
      let m_ = o.data || null;
      let d_ = o.dataType || "JSON";
      let c_ = typeof o.async == "undefined" ? true : o.async;
      let fn_ = o.success || null;
      let h_ = o.header || [];
      let isGet = t_.toLowerCase() == "get";
      let prms_ = [];
      if (m_) {
        for (let p_ in m_) {
          prms_.push(isGet ? $gP_(p_, m_[p_]) : $pP_(p_, m_[p_]));
        }
      }
      prms_.length
        ? (u_ = isGet
            ? u_ + (u_.indexOf("?") == -1 ? "?" : "&") + prms_.join("&")
            : u_)
        : null;
      let x_ = new XMLHttpRequest();
      x_.open(t_, u_, c_);
      x_.onreadystatechange = function onchange() {
        if (x_.readyState == 4) {
          if (x_.status == 200) {
            let responseText = x_.responseText.toString().trim();
            let retObj =
              d_ == "JSON"
                ? responseText
                  ? JSON.parse(responseText)
                  : {}
                : responseText;
            if (fn_) {
              fn_(retObj);
            }
          } else {
            console.error("Request exception ...");
          }
        }
      };
      for (let h in h_) {
        x_.setRequestHeader(h, h_[h]);
      }
      x_.send(isGet ? null : prms_.join("&"));
    },
    base64Encode: (str) => {
      const utf8 = $en_(str);
      const utf8Str = utf8.replace(/%(\w{2})/g, (m, a) =>
        String.fromCharCode("0x" + a),
      );
      return btoa(utf8Str);
    },
    base64Decode: (str) => {
      const utf8 = [...atob(str)]
        .map((item) => "%" + item.charCodeAt(0).toString(16))
        .join("");
      return decodeURIComponent(utf8);
    },
    parse: (str) =>
      typeof str == "object" ? str : Function(`return(${str})`)(),
    string: (o) => JSON.stringify(o),
    loadJs(a, b) {
      if (!a || a.length === 0) {
        throw new Error("Missing 'path' parameter !");
      }
      let script = $Ths.crtDom("<script>");
      script.src = a;
      script.type = "text/javascript";
      $w.document.getElementsByTagName("head")[0].appendChild(script);
      if (b) {
        script.onload = script.onreadystatechange = function () {
          if (
            !this.readyState ||
            this.readyState == "loaded" ||
            this.readyState == "complete"
          ) {
            b();
          }
          script.onload = script.onreadystatechange = null;
        };
      }
    },
    loadCss(a, b, rel) {
      if (!a || a.length === 0) {
        throw new Error("Missing 'path' parameter !");
      }
      let link = $Ths.crtDom("link");
      link.href = a;
      link.rel = rel || "stylesheet";
      link.type = "text/css";
      $Doc.getElementsByTagName("head")[0].appendChild(link);
      if (b) {
        link.onload = link.onreadystatechange = function () {
          if (
            !this.readyState ||
            this.readyState == "loaded" ||
            this.readyState == "complete"
          ) {
            b();
          }
          link.onload = link.onreadystatechange = null;
        };
      }
    },
    addStyle(styleText) {
      let style = $Ths.crtDom("style");
      style.type = "text/css";
      style.innerHTML = cssText;
      $Doc.getElementsByTagName("head")[0].appendChild(style);
      return style;
    },
    request(o) {
      if (!o.url) {
        throw new Error("Missing 'url' parameter !");
      }
      let d_ = o.data;
      let ifr_ = $Ths.crtDom("iframe");
      let id_ = "req-iframe-id-" + new Date().getTime();
      ifr_.id = id_;
      ifr_.name = id_;
      ifr_.style = "display:none";
      let fm_ = $Ths.crtDom("form");
      fm_.action = o.url;
      fm_.target = id_;
      fm_.method = o.type || "post";
      for (let n in d_) {
        let ipt = $Ths.crtDom("input");
        ipt.type = "hidden";
        ipt.name = n;
        ipt.value = d_[n];
        fm_.appendChild(ipt);
      }
      ifr_.appendChild(fm_);
      $Doc.body.appendChild(ifr_);
      fm_.submit();
      ifr_.onload = function () {
        let body = ifr_.contentDocument.body;
        let result = $$(body).text();
        $Doc.body.removeChild(ifr_);
        let data = JSON.parse(result);
        if (o.success) {
          o.success(data);
        }
      };
    },
    get(o) {
      if (!o.url) {
        throw new Error("Missing 'url' parameter !");
      }
      let ifr_ = $Ths.crtDom("iframe");
      let id_ = "get-iframe-id-" + new Date().getTime();
      ifr_.id = id_;
      ifr_.name = id_;
      ifr_.style = "display:none";
      ifr_.src = o.url;
      $Doc.body.appendChild(ifr_);
      ifr_.onload = function () {
        let body = ifr_.contentDocument.body;
        let result = $$(body).text();
        $Doc.body.removeChild(ifr_);
        let data = JSON.parse(result);
        if (o.success) {
          o.success(data);
        }
      };
    },
    join: (...str) => str.join(""),
  };
  for (let n in fn) {
    this[n] = fn[n];
  }
  return fn;
}, window);
